package com.franklin.ideaplugin.easytesting.linemarker;

import com.franklin.ideaplugin.easytesting.action.ExecuteMethodAction;
import com.intellij.codeInsight.daemon.LineMarkerInfo;
import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.editor.markup.GutterIconRenderer;
import com.intellij.pom.Navigatable;
import com.intellij.psi.PsiMethod;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.Collection;

/**
 * @author Franklin
 * @since 2021/9/6 19:58
 */
class SelectMethodLineMarkerInfo extends LineMarkerInfo<PsiMethod> {

    protected PsiMethod element;

    protected ExecuteMethodAction executeMethodAction;

    SelectMethodLineMarkerInfo(
        @NotNull PsiMethod element,
        @NotNull Icon icon,
        Navigatable navigatable,
        Collection<String> fixTargets
    ) {
        super(
                element,
                element.getNameIdentifier().getTextRange(),
                icon,
                interfaceClassName -> "Execute the method",
                (mouseEvent, interfaceClassName) -> {

                },
                GutterIconRenderer.Alignment.CENTER,
                () -> {
                    return String.join(",", fixTargets);
                }
        );
        this.element = element;
        this.executeMethodAction = new ExecuteMethodAction();
    }

    @Override
    public GutterIconRenderer createGutterRenderer() {
        return new LineMarkerGutterIconRenderer<>(this) {

            public AnAction getClickAction() {
                return executeMethodAction;
            }

            public boolean isNavigateAction() {
                return true;
            }

            @Override
            public @Nullable
            ActionGroup getPopupMenuActions() {
                return null;
            }

        };
    }

}
